package com.zxl.working.mapper.backend;

import com.zxl.working.entity.backend.PersonInfo;
import com.zxl.working.entity.dto.PersonInfoBankDto;

import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Qualifier;

@Mapper
@Qualifier("backEndSqlSessionTemplate")
public interface PersonInfoMapper {

    @Select("SELECT * FROM  person_info WHERE card_code=#{cardCode} limit 1")
    @Results({
            @Result(property = "personId",column = "person_id"),
            @Result(property = "personName",column = "person_name"),
            @Result(property = "cardType",column = "card_type"),
            @Result(property = "cardCode",column = "card_code"),
            @Result(property = "mobile",column = "mobile"),
            @Result(property = "cardStatus",column = "card_status"),
            @Result(property = "addStatus",column = "add_status"),
            @Result(property = "agreement",column = "agreement"),
            @Result(property = "errorMsg",column = "error_msg"),
            @Result(property = "loginId",column = "login_id"),
            @Result(property = "loginName",column = "login_name"),
            @Result(property = "cardImgOne",column = "card_img_one"),
            @Result(property = "cardImgTwo",column = "card_img_two"),
            @Result(property = "email",column = "email"),
            @Result(property = "introduction",column = "introduction")

    })
    PersonInfo qryPersonInfoByCardCode(@Param("cardCode") String cardCode);

    @Insert("insert into person_info(person_id,person_name,card_type,card_code,mobile,card_status,agreement,login_id,login_name)" +
            " values(#{personId},#{personName},#{cardType},#{cardCode},#{mobile},#{cardStatus},#{agreement},#{loginId},#{loginName})")
    void save(PersonInfo personInfo);

    @Select("SELECT i.person_id,i.person_name,i.mobile,i.card_code,b.card_no,b.`status` FROM  person_info i left join person_bank b on i.person_id = b.person_id WHERE i.card_code=#{cardCode} limit 1")
    @Results({
        @Result(property = "personId",column = "person_id"),
        @Result(property = "personName",column = "person_name"),
        @Result(property = "mobile",column = "mobile"),
        @Result(property = "cardCode",column = "card_code"),
        @Result(property = "cardNo",column = "card_no"),
        @Result(property = "status",column = "status")
    })
    PersonInfoBankDto findCardCode(@Param("cardCode")String cardCode);

}
